﻿using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json.Linq;
using System;
using System.Windows.Forms;

namespace LD.Tool
{
    public partial class ToolFTPUploadFrm : FrmToolBase
    {
        public ToolFTPUploadFrm()
        {
            InitializeComponent();
            this.btn_ok.Click += Btn_ok_Click;
            this.Shown += FrmTaskTool_Shown;
        }

        private void FrmTaskTool_Shown(object sender, EventArgs e)
        {
            Init();
        }

        private void Btn_ok_Click(object sender, EventArgs e)
        {
            JObject obj = new JObject(); ;
            obj.Add("dir", this.txt_dir.Text);
            obj.Add("dirNG", this.txt_dirNG.Text);
            obj.Add("subffix", this.txt_subffix.Text);
            obj.Add("isWarSave", this.chk_warSave.Checked);
            this.TB_Tool.Param = obj.ToString();
            this.Close();
        }
        private void Init()
        {
            if (this.TB_Tool.Param == null)
                return;
            JObject obj = JObject.Parse(this.TB_Tool.Param);

            this.txt_dir.Text = obj["dir"]?.ToString();
            this.txt_dirNG.Text = obj["dirNG"]?.ToString();
            this.txt_subffix.Text = obj["subffix"]?.ToString();
            this.chk_warSave.Checked = (bool)obj["isWarSave"];
        }

        private void btn_dir_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog folder = new FolderBrowserDialog())
            {
                folder.Description = "选择待上传的文件目录";
                folder.ShowNewFolderButton = true;
                if (folder.ShowDialog() == DialogResult.OK)
                {
                    this.txt_dir.Text = folder.SelectedPath;
                }
            }
        }

        private void btn_dirNG_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog folder = new FolderBrowserDialog())
            {
                folder.Description = "选择待上传的文件目录";
                folder.ShowNewFolderButton = true;
                if (folder.ShowDialog() == DialogResult.OK)
                {
                    this.txt_dirNG.Text = folder.SelectedPath;
                }
            }
        }
    }
}
